home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / dialoglib.lha / hcons.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-07  |  8.1 KB  |  302 lines

  1. #include <clib/macros.h>
  2. #include <proto/utility.h>
  3. #include "dialog.h"
  4. #ifdef DEBUG1
  5.     #include <stdio.h>
  6. #endif
  7.  
  8. /* filters for structure flag common among car and cdr */
  9. static ULONG getHConsStructure( DialogElement *de )
  10. {
  11.     DialogElement *car, *cdr;
  12.     ULONG hstructure = DESF_HBaseline;
  13.  
  14.     if( !de )
  15.         return 0;
  16.  
  17.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  18.         hstructure &= getDialogElementStructure( car );
  19.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  20.         hstructure &= getDialogElementStructure( cdr );
  21.     return hstructure | DESF_VBaseline;
  22. }
  23.  
  24. static VOID setupHCons( DialogElement *de )
  25. {
  26.     DialogElement *car, *cdr;
  27.     LONG alignment, mintop, minbottom, minheight, maxtop, maxbottom, maxheight;
  28.     ULONG substructure;
  29.  
  30.     if( !de )
  31.         return;
  32.  
  33.     alignment = GetTagData( DA_Alignment, 0, de->taglist );    /* currently unused */
  34.  
  35.     /* determine structure */
  36.     de->structure = getDialogElementStructure( de );
  37.  
  38.     /* these value are modified later */
  39.     setMinLeftExtent( de, 0 );
  40.     setMaxLeftExtent( de, 0 );
  41.     setMinRightExtent( de, 0 );
  42.     setMaxRightExtent( de, 0 );
  43.     if( de->structure & DESF_HBaseline )
  44.     {
  45.         setMaxTopExtent( de, 0 );
  46.         setMaxBottomExtent( de, 0 );
  47.     }
  48.     else
  49.         setMaxHeight( de, 0 );
  50.  
  51.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  52.     {
  53.         setupDialogElement( car );
  54.         de->idcmp_mask |= car->idcmp_mask;
  55.         substructure = getDialogElementStructure( car );
  56.  
  57.         /* modify Min/MaxLeftExtent to accomodate car */
  58.         if( substructure & DESF_VBaseline )
  59.         {
  60.             setMinLeftExtent( de, getMinLeftExtent( car ) + getMinRightExtent( car ) );
  61.             setMaxLeftExtent( de, getMaxLeftExtent( car ) + getMaxRightExtent( car ) );
  62.         }
  63.         else
  64.         {
  65.             setMinLeftExtent( de, getMinWidth( car ) );
  66.             setMaxLeftExtent( de, getMaxWidth( car ) );
  67.         }
  68.  
  69.         /* modify Min/MaxHeight or Min/MaxTop/BottomExtent to accomodate car */
  70.         if( substructure & DESF_HBaseline )
  71.         {
  72.             mintop = getMinTopExtent( car );
  73.             minbottom = getMinBottomExtent( car );
  74.             maxtop = getMaxTopExtent( car );
  75.             maxbottom = getMaxBottomExtent( car );
  76.             if( de->structure & DESF_HBaseline )
  77.             {
  78.                 if( mintop > getMinTopExtent( de ) )
  79.                     setMinTopExtent( de, mintop );
  80.                 if( minbottom > getMinBottomExtent( de ) )
  81.                     setMinBottomExtent( de, minbottom );
  82.                 if( maxtop > getMaxTopExtent( de ) )
  83.                     setMaxTopExtent( de, maxtop );
  84.                 if( maxbottom > getMaxBottomExtent( de ) )
  85.                     setMaxBottomExtent( de, maxbottom );
  86.             }
  87.             else
  88.             {
  89.                 minheight = mintop + minbottom;
  90.                 maxheight = maxtop + maxbottom;
  91.                 if( minheight > getMinHeight( de ) )
  92.                     setMinHeight( de, minheight );
  93.                 if( maxheight > getMaxHeight( de ) )
  94.                     setMaxHeight( de, maxheight );
  95.             }
  96.         }
  97.         else
  98.         {
  99.             minheight = getMinHeight( car );
  100.             maxheight = getMaxHeight( car );
  101.             if( minheight > getMinHeight( de ) )
  102.                 setMinHeight( de, minheight );
  103.             if( maxheight > getMaxHeight( de ) )
  104.                 setMaxHeight( de, maxheight );
  105.         }
  106.     }
  107.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  108.     {
  109.         setupDialogElement( cdr );
  110.         de->idcmp_mask |= cdr->idcmp_mask;
  111.         substructure = getDialogElementStructure( cdr );
  112.  
  113.         /* modify Min/MaxRightExtent to accomodate cdr */
  114.         if( substructure & DESF_VBaseline )
  115.         {
  116.             setMinRightExtent( de, getMinLeftExtent( cdr ) + getMinRightExtent( cdr ) );
  117.             setMaxRightExtent( de, getMaxLeftExtent( cdr ) + getMaxRightExtent( cdr ) );
  118.         }
  119.         else
  120.         {
  121.             setMinRightExtent( de, getMinWidth( cdr ) );
  122.             setMaxRightExtent( de, getMaxWidth( cdr ) );
  123.         }
  124.  
  125.         /* modify Min/MaxHeight or Min/MaxTop/BottomExtent to accomodate cdr */
  126.         if( substructure & DESF_HBaseline )
  127.         {
  128.             mintop = getMinTopExtent( cdr );
  129.             minbottom = getMinBottomExtent( cdr );
  130.             maxtop = getMaxTopExtent( cdr );
  131.             maxbottom = getMaxBottomExtent( cdr );
  132.             if( de->structure & DESF_HBaseline )
  133.             {
  134.                 if( mintop > getMinTopExtent( de ) )
  135.                     setMinTopExtent( de, mintop );
  136.                 if( minbottom > getMinBottomExtent( de ) )
  137.                     setMinBottomExtent( de, minbottom );
  138.                 if( maxtop > getMaxTopExtent( de ) )
  139.                     setMaxTopExtent( de, maxtop );
  140.                 if( maxbottom > getMaxBottomExtent( de ) )
  141.                     setMaxBottomExtent( de, maxbottom );
  142.             }
  143.             else
  144.             {
  145.                 minheight = mintop + minbottom;
  146.                 maxheight = maxtop + maxbottom;
  147.                 if( minheight > getMinHeight( de ) )
  148.                     setMinHeight( de, minheight );
  149.                 if( maxheight > getMaxHeight( de ) )
  150.                     setMaxHeight( de, maxheight );
  151.             }
  152.         }
  153.         else
  154.         {
  155.             minheight = getMinHeight( cdr );
  156.             maxheight = getMaxHeight( cdr );
  157.             if( minheight > getMinHeight( de ) )
  158.                 setMinHeight( de, minheight );
  159.             if( maxheight > getMaxHeight( de ) )
  160.                 setMaxHeight( de, maxheight );
  161.         }
  162.     }
  163. }
  164.  
  165. static ULONG layoutHCons( DialogElement *de, LayoutMessage *lm )
  166. {
  167.     DialogElement *car, *cdr;
  168.     LayoutMessage message;
  169.     LONG alignment;
  170.     LONG x, left, right, white, spare;
  171.     ULONG substructure, error = DIALOGERR_OK;
  172.  
  173.     if( !de )
  174.         return DIALOGERR_BAD_ARGS;
  175.     if( !lm )
  176.         return DIALOGERR_BAD_ARGS;
  177.  
  178. #ifdef DEBUG1
  179.     printf(
  180.     "layoutHCons : x %d, y %d, width %d, height %d, left %d, right %d, top %d, bottom %d\n",
  181.         lm->lm_X, lm->lm_Y, lm->lm_Width, lm->lm_Height,
  182.         lm->lm_Left, lm->lm_Right, lm->lm_Top, lm->lm_Bottom );
  183. #endif
  184.  
  185.     alignment = GetTagData( DA_Alignment, 0, de->taglist );    /* currently ignored */
  186.  
  187.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  188.     {
  189.         substructure = prepareMemberLayoutV( &message, de, car, lm );
  190.         x = lm->lm_X;
  191.         if( substructure & DESF_VBaseline )
  192.         {
  193.             LONG minleft, minright;
  194.  
  195.             minleft = getMinLeftExtent( car );
  196.             minright = getMinRightExtent( car );
  197.             white = lm->lm_Left - minleft - minright;
  198.             left = getMaxLeftExtent( car ) - minleft;
  199.             right = getMaxRightExtent( car ) - minright;
  200.             spare = left + right;
  201.             left = minleft + ( ( spare ) ? ( left * white ) / spare : 0 );
  202.             right = minright + ( ( spare ) ? ( right * white ) / spare : 0 );
  203.             prepareLayoutVBaseline( &message, left, right );
  204.             x -= right;
  205.         }
  206.         else
  207.         {
  208.             prepareLayoutNoVBaseline( &message, lm->lm_Left );
  209.             x -= lm->lm_Left;
  210.         }
  211.         prepareLayoutX( &message, x );
  212.         error = layoutDialogElement( car, &message, lm->lm_PreviousPtr );
  213.         if( error )
  214.             goto termination;
  215.     }
  216.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  217.     {
  218.         substructure = prepareMemberLayoutV( &message, de, cdr, lm );
  219.         x = lm->lm_X;
  220.         if( substructure & DESF_VBaseline )
  221.         {
  222.             LONG minleft, minright;
  223.  
  224.             minleft = getMinLeftExtent( cdr );
  225.             minright = getMinRightExtent( cdr );
  226.             white = lm->lm_Right - minleft - minright;
  227.             left = getMaxLeftExtent( cdr ) - minleft;
  228.             right = getMaxRightExtent( cdr ) - minright;
  229.             spare = left + right;
  230.             left = minleft + ( ( spare ) ? ( left * white ) / spare : 0 );
  231.             right = minright + ( ( spare ) ? ( right * white ) / spare : 0 );
  232.             prepareLayoutVBaseline( &message, left, right );
  233.             x += left;
  234.         }
  235.         else
  236.             prepareLayoutNoVBaseline( &message, lm->lm_Right );
  237.         prepareLayoutX( &message, x );
  238.         error = layoutDialogElement( cdr, &message, lm->lm_PreviousPtr );
  239.         if( error )
  240.             goto termination;
  241.     }
  242. termination:
  243.     return error;
  244. }
  245.  
  246. static DialogElement *matchHCons( DialogElement *de, MatchMessage *mm )
  247. {
  248.     DialogElement *car, *cdr, *match = NULL;
  249.  
  250.     if( !de )
  251.         return NULL;
  252.     if( !mm )
  253.         return NULL;
  254.  
  255.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  256.         if( match = mapDialogEvent( car, mm->mm_IntuiMsg ) )
  257.             goto termination;
  258.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  259.         if( match = mapDialogEvent( cdr, mm->mm_IntuiMsg ) )
  260.             goto termination;
  261. termination:
  262.     return match;
  263. }
  264.  
  265. static VOID clearHCons( DialogElement *de )
  266. {
  267.     DialogElement *car, *cdr;
  268.  
  269.     if( !de )
  270.         return;
  271.  
  272.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  273.         clearDialogElement( car );
  274.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  275.         clearDialogElement( cdr );
  276. }
  277.  
  278. ULONG dispatchHCons( struct Hook *hook, DialogElement *de, DialogMessage *dm )
  279. {
  280.     ULONG result;
  281.  
  282.     switch( dm->dm_MethodID )
  283.     {
  284.     case DIALOGM_GETSTRUCT:
  285.         result = getHConsStructure( de );
  286.         break;
  287.     case DIALOGM_SETUP:
  288.         setupHCons( de );
  289.         break;
  290.     case DIALOGM_LAYOUT:
  291.         result = layoutHCons( de, (LayoutMessage *)dm );
  292.         break;
  293.     case DIALOGM_MATCH:
  294.         result = (ULONG)matchHCons( de, (MatchMessage *)dm );
  295.         break;
  296.     case DIALOGM_CLEAR:
  297.         clearHCons( de );
  298.         break;
  299.     }
  300.     return result;
  301. }
  302.